package com.wuliwu.autoapi;

import com.wuliwu.autoapi.bean.Result;
import com.wuliwu.autoapi.service.ApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 可视化接口调试
 */
@Controller
@RequestMapping(value = "/api")
public class ApiController {

    @Autowired
    private ApiService apiService;

    @RequestMapping("")
    public String index(Model model) {
        model.addAttribute("list", apiService.getFunctions());
        return "/api/index.html";
    }

    @RequestMapping("/function")
    public String function() {
        return "/api/function.html";
    }

    @GetMapping("/getFunction")
    @ResponseBody
    public Result getFunction(String url) {
        return Result.success(apiService.getFunction(url));
    }

    @GetMapping("/list")
    @ResponseBody
    public Result list() {
        List list = apiService.getFunctions();
        return Result.success(list);
    }

}
